#include "Container.h"
#include <log4qt/logmanager.h>

Container::Container(void) : isDestroyed(false), log(Log4Qt::Logger::logger("poc.Container"))
{
}

Container::~Container(void)
{
	destroy();
}

void Container::initSystem()
{
	log->info("initializing system.");
}
void Container::initLogSystem(const QString& path)
{
	Log4Qt::PropertyConfigurator::configure(path);
	
}
void Container::initCms()
{
	log->info("initializing cms lib and factory manager.");
	activemq::library::ActiveMQCPP::initializeLibrary();
	connectionCfg = new ConnectionConfig();
	factoryManager = new  FactoryManager (connectionCfg);
}
void Container::destroy()
{
	if(isDestroyed)
	{
		return;
	}
	isDestroyed = true;
	try
	{
		
		if(factoryManager != NULL)
		{
			try{delete factoryManager;}
			catch(...){}
			factoryManager = NULL;
		}

		if(connectionCfg != NULL)
		{
			try{delete connectionCfg;}catch(...){}
			connectionCfg = NULL;
		}
		activemq::library::ActiveMQCPP::shutdownLibrary();
		google::protobuf::ShutdownProtobufLibrary();
		log->info("destroyed Container.");
		Log4Qt::LogManager::shutdown();
	}
	catch(...)
	{
	}
}
